//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package atomgit_triger

import (
	"fmt"
	"testing"
)

const _ISSUE_HOOK_DATA = `
{
  "action": "opened",
  "issue": {
    "url": "https://api.atomgit.com/repos/openlinksaas/test/issues/1",
    "repository_url": "https://api.atomgit.com/repos/openlinksaas/test",
    "labels_url": "https://api.atomgit.com/repos/openlinksaas/test/issues/1/labels{/name}",
    "comments_url": "https://api.atomgit.com/repos/openlinksaas/test/issues/1/comments",
    "events_url": "https://api.atomgit.com/repos/openlinksaas/test/issues/1/events",
    "html_url": "https://atomgit.com/openlinksaas/test/issues/1",
    "id": "67a57f1725933b368d96cff1",
    "number": "1",
    "title": "测试一下",
    "user": {
      "id": "64fae54f49d9355e7a863eb6",
      "type": "User",
      "site_admin": false,
      "login": "openlinksaas",
      "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
      "url": "https://api.atomgit.com/openlinksaas",
      "html_url": "https://atomgit.com/openlinksaas",
      "followers_url": "https://api.atomgit.com/openlinksaas/followers",
      "following_url": "https://api.atomgit.com/openlinksaas/following{/other_user}",
      "organizations_url": "https://api.atomgit.com/openlinksaas/orgs",
      "repos_url": "https://api.atomgit.com/openlinksaas/repos"
    },
    "labels": [],
    "state": "open",
    "locked": false,
    "assignee": null,
    "milestone": {},
    "created_at": "2025-02-07T11:33:43+08:00",
    "updated_at": "2025-02-07T11:33:43+08:00",
    "closed_at": null,
    "body": "<p>1111111</p>\n",
    "state_reason": null
  },
  "repository": {
    "id": 37070260,
    "name": "test",
    "full_name": "openlinksaas/test",
    "private": true,
    "owner": {
      "id": "64fae54f49d9355e7a863eb6",
      "type": "User",
      "site_admin": false,
      "login": "openlinksaas",
      "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
      "url": "https://api.atomgit.com/openlinksaas",
      "html_url": "https://atomgit.com/openlinksaas",
      "followers_url": "https://api.atomgit.com/openlinksaas/followers",
      "following_url": "https://api.atomgit.com/openlinksaas/following{/other_user}",
      "organizations_url": "https://api.atomgit.com/openlinksaas/orgs",
      "repos_url": "https://api.atomgit.com/openlinksaas/repos"
    },
    "html_url": "https://atomgit.com/openlinksaas/test",
    "description": "",
    "url": "https://api.atomgit.com/repos/openlinksaas/test",
    "hooks_url": "https://api.atomgit.com/repos/openlinksaas/test/hooks",
    "branches_url": "https://api.atomgit.com/repos/openlinksaas/test/branches{/branch}",
    "tags_url": "https://api.atomgit.com/repos/openlinksaas/test/tags",
    "git_tags_url": "https://api.atomgit.com/repos/openlinksaas/test/git/tags{/sha}",
    "git_refs_url": "https://api.atomgit.com/repos/openlinksaas/test/git/refs{/sha}",
    "trees_url": "https://api.atomgit.com/repos/openlinksaas/test/trees{/sha}",
    "commits_url": "https://api.atomgit.com/repos/openlinksaas/test/commits{/sha}",
    "comments_url": "https://api.atomgit.com/repos/openlinksaas/test/comments{/number}",
    "issue_comment_url": "https://api.atomgit.com/repos/openlinksaas/test/issues/comments{/number}",
    "merges_url": "https://api.atomgit.com/repos/openlinksaas/test/merges",
    "issues_url": "https://api.atomgit.com/repos/openlinksaas/test/issues{/number}",
    "pulls_url": "https://api.atomgit.com/repos/openlinksaas/test/pulls{/number}",
    "milestones_url": "https://api.atomgit.com/repos/openlinksaas/test/milestones{/number}",
    "labels_url": "https://api.atomgit.com/repos/openlinksaas/test/labels{/name}",
    "releases_url": "https://api.atomgit.com/repos/openlinksaas/test/releases{/id}",
    "created_at": "2025-02-07 10:53:55",
    "git_url": "git://atomgit.com/openlinksaas/test.git",
    "ssh_url": "git@atomgit.com:openlinksaas/test.git"
  },
  "sender": {
    "id": "64fae54f49d9355e7a863eb6",
    "type": "User",
    "site_admin": false,
    "login": "openlinksaas",
    "avatar_url": "https://file.atomgit.com/uploads/user/1694222084215_2176.png",
    "url": "https://api.atomgit.com/openlinksaas",
    "html_url": "https://atomgit.com/openlinksaas",
    "followers_url": "https://api.atomgit.com/openlinksaas/followers",
    "following_url": "https://api.atomgit.com/openlinksaas/following{/other_user}",
    "organizations_url": "https://api.atomgit.com/openlinksaas/orgs",
    "repos_url": "https://api.atomgit.com/openlinksaas/repos"
  }
}
`

func TestExtractIssueHookAttr(t *testing.T) {
	attrList, err := ExtractIssueHookAttr([]byte(_ISSUE_HOOK_DATA))
	if err != nil {
		t.Fatal(err)
		t.FailNow()
	}
	fmt.Println(attrList)
}
